var express = require('express');
var router = express.Router();
var userctrl = require('../code/users');


/* GET users listing. */
router.post('/add', function (req, res, next) {
    userctrl.userctrl.add(req.body, function (json_data) {
        if (json_data.code == 1) {
            req.session.winall = 'ok' + req.body.username;
        }
        res.send(json_data);
    })
});
router.post('/login', function (req, res, next) {
    userctrl.userctrl.login(req.body, function (json_data) {
        if (json_data.success) {
            req.session.winall = req.body.username;
        }
        res.send(json_data);
    })
});
router.get('/betview', function (req, res, next) {
    userctrl.userctrl.betview(req, function (json_data) {
        res.send(json_data);
    })
});
router.get('/loginout', function (req, res, next) {
    req.session.winall = '';
    res.send({success: true, msg: '退出成功'});
});
router.post('/bet', function (req, res, next) {
    userctrl.userctrl.bet(req, function (json_data) {
        res.send(json_data);

    })
});
router.post('/edit', function (req, res, next) {
    userctrl.userctrl.edit(req, function (json_data) {
        res.send(json_data);
    })
});


module.exports = router;
